import REQUSET from './$requset.js';
import $wx from './$wxes.js';

var showModal;

REQUSET.SET_GLOBAL_CONFIG(global => {
  global._header = () => {
    return { token: wx.getStorageSync('token') }
  }

  global._success = (res, resolve) => {
    let rd = res.data;
    if (rd.code == 401) {
      if (!showModal) {
        showModal = wx.showModal;
        showModal({
          title: '提示',
          content: '请登录',
          success(res) {
            if (res.confirm) {
              showModal = null;
              wx.navigateTo({ url: '/pages/login/login' })
            } else {
              showModal = null;
            }
          }
        });
      }
    } else if (rd.code == 1) {
      resolve([true, rd.data, rd.msg]);
    } else {
      resolve([false, rd, rd.msg || '请求失败']);
    }
  }
});

const HOST = 'http://huatu.ewent.cn';

// 登录
export const login = (data) => REQUSET.POST(HOST + '/addons/litestore/api.user/login_hawk', data);

// index
export const index = (data) => REQUSET.GET(HOST + '/api/index/index', data);

// home
export const home = (data) => REQUSET.GET(HOST + '/addons/litestore/api.index/index', data);

// 领取优惠券
export const getAuthorDetail = (data) => REQUSET.POST(HOST + '/addons/litestore/api.Apiauthor/getById', data);

// 商品列表
export const goodsList = (data) => REQUSET.POST(HOST + '/api/good/index', data);

// 获取商品分类
// export const getGoodsType = (data) => REQUSET.GET(HOST + '/addons/litestore/api.Category/Showlist', data);

// 获取商品列表
export const getGoodsList = (data) => REQUSET.GET(HOST + '/addons/litestore/api.Category/Showlist', data);

// 获取商品列表
export const pay = (data) => REQUSET.POST(HOST + '/addons/litestore/api.order/orderBy', data);

// 商品详情
export const goodDetail = (data) => REQUSET.POST(HOST + '/addons/litestore/api.goods/detail', data);

// 话题详情
export const getTopicDetail = (data) => REQUSET.GET(HOST + '/addons/litestore/api.article/getById', data);

// 作者作品
export const authorProduction = (data) => REQUSET.GET(HOST + '/addons/litestore/api.Apiauthor/getGoodsByAuthorId', data);

// 赞/踩
export const isLike = (data) => REQUSET.POST(HOST + '/addons/litestore/api.article/like', data);

// 收藏商品
export const collectGood = (data) => REQUSET.POST(HOST + '/addons/litestore/api.goods/goodsCollect', data);

// 加入购物车
export const addCart = (data) => REQUSET.POST(HOST + '/addons/litestore/api.cart/add', data);

// 删除购物车商品
export const deleteCartCommodity = (data) => REQUSET.POST(HOST + '/addons/litestore/api.cart/delete', data);

// 购物车列表
// export const cartList = (data) => REQUSET.POST(HOST + '/api/cart/index', data);

// 生成订单
export const createOrder = (data) => REQUSET.GET(HOST + '/addons/litestore/api.order/creatOrder', data);

// 素材列表
export const diydetail = (data) => REQUSET.POST(HOST + '/addons/litestore/api.index/diydetail', data);

// 用户信息
export const getUserInfo = (data) => REQUSET.POST(HOST + '/addons/litestore/api.uservue/index', data);

// 设置个人信息
export const setUserInfo = (data) => REQUSET.POST(HOST + '/addons/litestore/api.user/Updata_user_hawk', data);

// 上传文件
export const uploadFile = HOST + '/api/common/upload';

// 系统消息
export const getMsg = (data) => REQUSET.POST(HOST + '/addons/litestore/api.sendnotice/getList', data);

// 设为已读消息
export const setMsg = (data) => REQUSET.POST(HOST + '/addons/litestore/api.sendnotice/updateStatus', data);

// 获取积分
export const getScore = (data) => REQUSET.POST(HOST + '/addons/litestore/api.user/scoreList', data);

// 获取优惠券
export const getMyCoupons = (data) => REQUSET.POST(HOST + '/addons/litestore/api.Apicoupon/getList', data);

// 领取优惠券
export const getDiscountCoupon = (data) => REQUSET.POST(HOST + '/addons/litestore/api.Apicoupon/getById', data);

// 素材列表
export const getMaterialList = (data) => REQUSET.POST(HOST + '/addons/litestore/api.index/diygood', data);

// 获取素材详情
export const getMaterialDetail = (data) => REQUSET.POST(HOST + '/api/user/notice', data);

// 获取卡纸
export const getPaperboardList = (data) => REQUSET.POST(HOST + '/addons/litestore/api.index/kzcolor', data);

// 获取购物车列表
export const getCartList = (data) => REQUSET.POST(HOST + '/addons/litestore/api.cart/getlists', data);

// 订单列表
export const orderList = (data) => REQUSET.POST(HOST + '/addons/litestore/api.order/my', data);

// 退款列表
export const refundList = (data) => REQUSET.POST(HOST + '/addons/litestore/api.order/tuikuan', data);

// 收货
export const finish = (data) => REQUSET.POST(HOST + '/addons/litestore/api.order/finish', data);

// 退款
export const refund = (data) => REQUSET.POST(HOST + '/addons/litestore/api.order/tuikuan', data);

// 评论
export const comment = (data) => REQUSET.POST(HOST + '/addons/litestore/api.order/addcommon', data);

// 主题
export const getRemmadDing = (data) => REQUSET.POST(HOST + '/addons/litestore/api.goods/getRemmadDing', data);

// 选中商品
export const getStatus = (data) => REQUSET.POST(HOST + '/addons/litestore/api.cart/getStatus', data);

// 带支付
export const orderPay = (data) => REQUSET.POST(HOST + '/addons/litestore/api.order/order_pay', data);

// 图文信息
export const picWirth = (data) => REQUSET.GET(HOST + '/addons/litestore/api.index/picWirth', data);

// 用户说明
export const userAgreement = (data) => REQUSET.GET(HOST + '/addons/litestore/api.index/userAbout', data);

// 用户说明
export const createDraw = (data) => REQUSET.POST(HOST + '/addons/litestore/api.goods/createImg', data);


